<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script src="/static/jquery-2.1.4.min.js"> </script>
<form action="" method="post">
    {% csrf_token %}

    <p >用户名:<input type="text" name="username"></p>
    <p>密码:<input type="password" name="password"></p>
    <button type="submit">提交</button>

</form>
    <input type="button" id="btn" value="ajax提交">
<script>
    $('#btn').click(function () {
        var name = $("input[name='username']").val();
        var password = $("input[name='password']").val();
        $.ajax({
            url:"",
            type:"post",
            dataType: 'json',
            contentType: "application/json",
            data:JSON.stringify({
                "name":name,
                "password":password,
            }),
            success:function (res) {
                console.log(res);

            }
        })
    })
</script>
</body>
</html>